﻿using System;
using System.Net;
using System.Windows;
using SilverlightClientLibrary.Utils;

namespace SilverlightClientLibrary.Messages
{
    public class PointMessage : LittleMessage
    {
        public Point Point { get; private set; }

        public PointMessage(Point p)
            : base()
        {
            Point = p;
        }

        public override byte[] Encode()
        {
            byte[] bytes = Point.EncodePoint();
            byte[] retArr = new byte[this.BufferSize];
            retArr[0] = (byte)MessageId.PointMessage;
            bytes.CopyTo(retArr, 2);
            return retArr;
        }

        public override Message Decode(byte[] bytes)
        {
            byte[] pointBuffer = new byte[bytes.Length];
            Array.Copy(bytes, 2, pointBuffer, 0, this.BufferSize - 2);
            Point = Point.DecodePoint(pointBuffer);
            return this;
        }
    }
}
